package com.emm.yixun.mobile.ui.customer;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.emm.yixun.mobile.R;
import com.emm.yixun.mobile.model.GetTagListBean;

import java.util.List;

/**
 * Created by tangxin on 2017/9/22.
 */

public class TagListAdapter extends BaseAdapter {

    List<GetTagListBean.TagList> tagList;

    public TagListAdapter(List<GetTagListBean.TagList> tagList) {
        this.tagList = tagList;
    }

    public void setTagListBean(List<GetTagListBean.TagList> tagList) {
        this.tagList = tagList;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return null == tagList ? 0 : tagList.size();
    }

    @Override
    public Object getItem(int position) {
        return null == tagList ? null : tagList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ItemView itemView = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_investigation_item, null);
            itemView = new ItemView();
            itemView.tvTitle = (TextView) convertView.findViewById(R.id.tv_title);
            convertView.setTag(itemView);
        } else {
            itemView = (ItemView) convertView.getTag();
        }
        itemView.tvTitle.setText(tagList.get(position).getTagName());
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                itemClick.item(tagList.get(position), position);
            }
        });
        return convertView;
    }

    public static class ItemView {

        TextView tvTitle;

    }

    itemClick itemClick;

    public void setItemClick(itemClick itemClick) {
        this.itemClick = itemClick;
    }

    interface itemClick {
        void item(GetTagListBean.TagList itemBean, int position);
    }

}
